package com.websocket.util;

import jodd.mail.Email;
import jodd.mail.SendMailSession;
import jodd.mail.SmtpServer;
import jodd.mail.SmtpSslServer;

import java.util.Map;

/**
 * 邮件相关工具
 * Created by simon on 5/23/17.
 */
public class EmailUtils {

    public static void send(String emails[], String emialTitle, String templateName, Map<String, Object> parmamsMap) {
//        SmtpServer<?> smtp = SmtpSslServer.create("smtp.mxhichina.com", 465);
//        smtp.authenticateWith("service@www.dtxzw.com", "Aa812135023");
//        SendMailSession session = smtp.createSession();
//        File file = new File(ConstantsUtil.Path.getPath() + templateName);
//        String content = filetoString(file, parmamsMap);
//        Email email = Email.create().from("service@www.dtxzw.com").subject(emialTitle)// 设置了主题
//                .to(emails).addHtml(content);
//        session.open();
//        session.sendMail(email);
//        session.close();
    }

    public static void main(String[] args) {

        send("zhangxiangfeng@kuaicto.com", "报错报告", "系统出现bug");

        System.out.println("ok");
    }

    public static void send(String to, String subject, String body) {
        SmtpServer<?> smtp = SmtpSslServer.create("smtp.openread.cn", 465);
        smtp.authenticateWith("error@openread.cn", "log@er;mYu>7FAD");
        SendMailSession session = smtp.createSession();


        Email email = Email.create().from("error@openread.cn").subject(subject)// 设置了主题
                .to(to).addText(body, Contains.UTF_8);
        session.open();
        session.sendMail(email);
        session.close();
    }

}
